package zjh_20230406;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

public class Demo02 {
    public static void main(String[] args) {
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            Socket socket = new Socket(localHost,8888);
            OutputStream outputStream = socket.getOutputStream();
            FileInputStream fileInputStream = new FileInputStream("C:\\Users\\dell\\Pictures\\Saved Pictures\\dog.jpg");
            outputStream.write(fileInputStream.readAllBytes());
            fileInputStream.close();

            System.out.println("发送成功");
            InputStream inputStream = socket.getInputStream();

            byte[] bytes = new byte[1024];
            int read = inputStream.read(bytes);
            System.out.println(new String(bytes,0,read));

            outputStream.close();
            inputStream.close();
            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
